﻿using System;
using System.Collections.Generic;
using PacketRush.Core;

namespace PacketRush.Services.UserManagement
{
    public abstract class NetUserService
    {
        /// <summary>
        /// Raised when a user changes their name
        /// </summary>
        public event EventHandler<NetUserNameChangeEventArgs> UserChangedName;

        /// <summary>
        /// Occurs when a user changes their name
        /// </summary>
        /// <param name="netConnectionId">The id of the connection</param>
        /// <param name="oldName">The users old name</param>
        /// <param name="newName">The users new name</param>
        protected void OnUserChangedName(int connectionId, string oldName, string newName)
        {
            if (UserChangedName != null)
            {
                UserChangedName(this, new NetUserNameChangeEventArgs(connectionId, oldName, newName));
            }
        }

        /// <summary>
        /// Raised when a user is added to the service
        /// </summary>
        public event EventHandler<NetEventArgs> UserAdded;

        /// <summary>
        /// Occurs when a user is added to the service
        /// </summary>
        /// <param name="netConnectionId">The id of the user that was added</param>
        protected void OnUserAdded(int connectionId)
        {
            if (UserAdded != null)
            {
                UserAdded(this, new NetEventArgs(connectionId));
            }
        }

        /// <summary>
        /// Raised when a user is removed from the service
        /// </summary>
        public event EventHandler<NetEventArgs> UserRemoved;

        /// <summary>
        /// Occurs when a user is removed from the service
        /// </summary>
        /// <param name="netConnectionId">The id of the user that was removed</param>
        protected void OnUserRemoved(int connectionId)
        {
            if (UserRemoved != null)
            {
                UserRemoved(this, new NetEventArgs(connectionId));
            }
        }

        private Dictionary<int, NetUser> _Users = new Dictionary<int, NetUser>(16);
        public Dictionary<int, NetUser> Users
        {
            get
            {
                return _Users;
            }
        }
    }
}
